package com.itheima.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.ResourceBundle;

public class JedisUtils {
    private static JedisPool jp;
    static{
        //加载文件必须放在类路径下，加载文件时，只需要给不包含后缀的文件名即可
        //该对象是实现国际化操作的
        ResourceBundle bundle = ResourceBundle.getBundle("redis");
        int maxTotal = Integer.parseInt(bundle.getString("redis.maxTotal"));
        int maxIdel = Integer.parseInt(bundle.getString("redis.maxIdel"));
        String host = bundle.getString("redis.host");
        int port = Integer.parseInt(bundle.getString("resis.port"));


        //Jedis连接池配置
        JedisPoolConfig jpc = new JedisPoolConfig();
        jpc.setMaxTotal(maxTotal);
        jpc.setMaxIdle(maxIdel);
        jp=new JedisPool(jpc,host,port);
    }

    public static Jedis getJedis(){
        return jp.getResource();
    }
}
